package java_012_zuoye07;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class java04 {
	public static void main(String[] args) throws IOException  {
		File srcFile = new File("D:\\a");
		File destFile = new File("E:\\copy");
		copyFile(destFile,srcFile);
	}
	private static void copyFile(File destFile, File srcFile) throws IOException {
		System.out.println(destFile.mkdirs());
		File[] src =srcFile.listFiles();
		if(src!=null){
			for(File c : src){
				if(c.isFile()){
					FileInputStream fis = new FileInputStream(c);
					FileOutputStream fos = new FileOutputStream(new File(destFile,c.getName()));
					byte[] bytes = new byte[2024];
					int len;
					while((len=fis.read(bytes))!=-1){
						fos.write(bytes,0,len);
					}
					fos.close();
					fis.close();
				}else{
					copyFile(new File(destFile,c.getName()),c);
				}
			}
		}
	}
}
